using System.Collections.Generic;
using System.Linq;
using log4net;
using System.Reflection;

namespace AgileDashboard.AppCode
{
    /// <summary>
    /// A base class for all DTOs that represent Version one entities
    /// </summary>
    public class VersionOneEntity
    {
        internal static Dictionary<string, string> BuildVersionOneAttributeDictionary<T>()
        {
            var dict = new Dictionary<string, string>();

            var props = typeof(T).GetProperties();
            foreach (var prop in props)
            {
                var propattr = prop.GetCustomAttributes(false);

                object attr = (from row in propattr where row.GetType() == typeof(VersionOneAttributeNameAttribute) select row).FirstOrDefault();
                if (attr == null)
                {
                    continue;
                }

                var myattr = (VersionOneAttributeNameAttribute)attr;
                dict.Add(prop.Name, myattr.AttributeName);
            }

            return dict;
        }
    }
}